﻿Imports System.Activities
Imports System.Activities.Presentation.Metadata
Imports System.ComponentModel
Imports System.Drawing
Imports System.Activities.Presentation

Public Class WMISYSGetEventLog
    Inherits WMIExecuteActivityBase

    Public Property LogType As InArgument(Of String) = "System"
    Public Property Condition As InArgument(Of String)


    Public Sub New()
        Me.DisplayName = My.Resources.GetEventLogDisplayName
    End Sub

    Protected Overrides Function BeginExecute(ByVal context As AsyncCodeActivityContext, ByVal callback As AsyncCallback, ByVal state As Object) As IAsyncResult
        MyBase._target = "Win32_NTLogEvent"
        Dim logtype = context.GetValue(Me.LogType)
        If logtype Is Nothing Then logtype = "System"
        Dim conditionStrings = context.GetValue(Me.Condition)
        If conditionStrings Is Nothing Then
            conditionStrings = "LogFile='" + logtype + "'"
        Else
            conditionStrings = "LogFile='" + logtype + "' and " + conditionStrings
        End If
        MyBase._where = conditionStrings
        MyBase._service = "cimv2"
        Return MyBase.BeginExecute(context, callback, state)
    End Function

    Protected Overrides Sub CacheMetadata(metadata As CodeActivityMetadata)
        MyBase.CacheMetadata(metadata)

        Dim build As New AttributeTableBuilder
        build.AddCustomAttributes(Me.GetType,
                                      New DesignerAttribute(GetType(WMIDefaultActivityDesigner), GetType(ActivityDesigner)),
                                      New ToolboxBitmapAttribute(Me.GetType, "WmiDefault.png"))
        build.AddCustomAttributes(GetType(WMISYSGetEventLog), "LogType",
                                      New CategoryAttribute(My.Resources.CategoryDetail),
                                      New DisplayNameAttribute(My.Resources.LogTypeDisplay),
                                      New DescriptionAttribute(My.Resources.LogTypeDescription))
        build.AddCustomAttributes(GetType(WMISYSGetEventLog), "Condition",
                                      New CategoryAttribute(My.Resources.CategoryDetail),
                                      New DisplayNameAttribute(My.Resources.ConditionDisplay),
                                      New DescriptionAttribute(My.Resources.ConditionDescription))

        MetadataStore.AddAttributeTable(build.CreateTable)
    End Sub

End Class
